######################################################
#   Omega Analyses in Different R Packages
######################################################


#~~~~~~~~~~~~~~ R package "MBESS" ~~~~~~~~~~~~~~~~~~#

# Kelley (2017) 

library(MBESS)

# interval.type = "ml" indicates that the method used to find confidence interval is ml.
# Other methods are available depending on the needs of the study.

ci.reliability(data = myData, type = "omega", interval.type = "ml", conf.level = 0.95)
## $est
## [1] 0.8144169
## 
## $se
## [1] 0.01702632
## 
## $ci.lower
## [1] 0.781046
## 
## $ci.upper
## [1] 0.8477879
## 
## $conf.level
## [1] 0.95
## 
## $type
## [1] "omega"
## 
## $interval.type
## [1] "maximum likelihood (wald ci)"
# coefficient alpha
ci.reliability(data = myData, type = "alpha", interval.type = "ml", conf.level = 0.95)
## $est
## [1] 0.7861023
## 
## $se
## [1] 0.01715837
## 
## $ci.lower
## [1] 0.7524725
## 
## $ci.upper
## [1] 0.8197321
## 
## $conf.level
## [1] 0.95
## 
## $type
## [1] "alpha"
## 
## $interval.type
## [1] "maximum likelihood (wald ci)"
#~~~~~~~~~~~~~~ R package "semTools"  ~~~~~~~~~~~~~~~~~~#

# Pornprasertmanit, Miller, Schoemann, & Rosseel (2013)

# Three omega estimates are available in this package.
# In addition to the conventional coefficient omega reported in the following, 
# an omega estimate that accounted for correlated measurement errors
# and the hierarchical omega can also be calculated.
# Details can be found in the package manual.

library(lavaan)
## This is lavaan 0.5-20
## lavaan is BETA software! Please report any bugs.
## 
## Attaching package: 'lavaan'
## The following object is masked from 'package:MBESS':
## 
##     cor2cov
model <- 'f =~ x1 + x2 + x3 + x4 + x5 + x6'
fit <- cfa(model, data = myData)

library(semTools)
## 
## ###############################################################################
## This is semTools 0.4-11
## All users of R (or SEM) are invited to submit functions or ideas for functions.
## ###############################################################################
## 
## Attaching package: 'semTools'
## The following object is masked from 'package:MBESS':
## 
##     ci.reliability
reliability(fit)[2, 1]
## [1] 0.814417
# coefficient alpha
reliability(fit)[1, 1]
## [1] 0.7861023
#~~~~~~~~~~~~~~ R package "coefficientalpha" ~~~~~~~~~~~~~~~~~~#

# Zhang & Yuan (2015)

# This R package provides robust estimates of alpha and omega 
# as well as the corresponding confidence intervals
# to deal with both outlying observations and missing data.

library(coefficientalpha)
## Loading required package: rsem
## Loading required package: MASS
# Varphi refers to the downweighting rate (for the outlying observations);
# by setting varphi at 0, the conventional non-robust omega is calculated.
summary(omega(myData, varphi = 0, se = TRUE))
## Test of homogeneity
## The robust F statistic is  0.93 
## with a p-value  0.4995 
## 
## The omega is 0.8144169 with the standard error 0.01661408.
## The estimated omega is 
##   omega                      0.814
##   se                         0.017
##   p-value (omega>0)          0.000
##   Confidence interval        0.782       0.847
## 
## 
## Test of homogeneity
##   The robust F statistic is  0.93 
##   with a p-value  0.4995 
##   Note. The robust test failed to reject the assumption of homogeneity.
# coefficient alpha
summary(alpha(myData, varphi = 0, se = TRUE))
## Test of tau-equavilence
## The robust F statistic is  11.717 
## with a p-value  0 
## **The F test rejected tau-equavilence**
## 
## The alpha is 0.7861023 with the standard error 0.01744227.
## The estimated alpha is 
##   alpha                      0.786
##   se                         0.017
##   p-value (alpha>0)          0.000
##   Confidence interval        0.752       0.820
## 
## 
## Test of tau-equivalence 
##   The robust F statistic is  11.717 
##   with a p-value  0 
##   Note. The robust test rejected the tau-equivalence assumption.


